-
Notifications
You must be signed in to change notification settings - Fork 40
Sp6 to Sp7 add missing constraints and tables #7643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Triggered by 17da256 on branch refs/heads/issue-7551
|
I've added fixes for all of the unit tests that were failing in main. Currently, there are some unit tests failing specifically because of the new tables added from Specify 6 that have multi-field primary keys. This is causing issues with our django, datamodel, and sqlalchemy code. Working through different options for workarounds. |
|
Some of the new tables that need to be added from sp6 have multi-field primary keys, which is causing a lot of issues for our datamodel to sqlalchemy model generation. I create a solution where these will be present in the Django model, but skip the creation for the sqlalchemy model so we can go ahead and finish this issue. We can worry about the sqlalchemy version of the model another time. |
|
Got the many-to-many fields working in the Django model, and got the unit tests working. Ready for review. |
|
Looks good, thanks for removing those unused Specify 6 tables 👍 |
See related (and first) #7683
|
Hey everyone! While I was testing this PR, I ran into an issue with databases created from the Specify 6. Specifically, the issue was caused due to Django expecting and using the Primary Key from the model when using the relationships, which does not exist in the many to many tables from Specify 6. To fix this, I moved the many to many code to its own migration outside of the initial migration and handled migrating the tables from Specify 6 to the new consistent format. See the changes in a788c8c..43bc97d. Some additional information about the migration is available in the migration itself: specify7/specifyweb/specify/migrations/0043_normalize_many_to_many.py Lines 25 to 37 in 355dda1
To facilitate the migration, we utilize Redis to store the old values of the Many to Many tables during the time the older tables are torn down and reconstructed. The stored records are then later populated into the new tables. specify7/specifyweb/specify/migrations/0043_normalize_many_to_many.py Lines 11 to 23 in 355dda1
Another caveat with this storage procedure is its memory usage. |
| ('createdbyagent', models.ForeignKey(db_column='CreatedByAgentID', null=True, on_delete=specifyweb.specify.models.protect_with_blockers, related_name='+', to='specify.agent')), | ||
| ('modifiedbyagent', models.ForeignKey(db_column='ModifiedByAgentID', null=True, on_delete=specifyweb.specify.models.protect_with_blockers, related_name='+', to='specify.agent')), | ||
| ('parent', models.ForeignKey(db_column='ParentItemID', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='children', to='specify.taxontreedefitem')), | ||
| ('parent', models.ForeignKey(db_column='ParentItemID', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='specify.taxontreedefitem')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what prompted the on delete behavior change of TaxonTreeDefItem -> parent from 76cec14?
Was it some comment about delete blockers from #7647, #6671, or #7674?
I imagine if this a necessary change we'll have to apply the same change to other trees.
Maybe we can look into the delete and delete blocker behavior for TreeDefItem tables?
Fixes #7551
Fixes #7617
Fixes #7626
This PR adds Django model definitions, constraints, and migrations for several legacy join tables and related entities that were present in existing Specify databases but missing from freshly initialized Sp7 databases.
These changes are based on a systematic comparison between an existing production database schema and a newly created schema, with the goal of ensuring that new databases accurately reflect the constraints and relationships relied on by legacy data and workflows.
Here is a link to an example of the difference between an Sp6 and Sp7 created database schema dump: https://www.diffchecker.com/qdMfXJCj/
After analyzing many different schema dumps, the schema differences between databases creation in Sp6 and Sp7, the following was found for constant differences:
16 Missing Foreign Key Constraints:
0 missing unique constraints were found, actually Sp7 create database had a few extra unique constrains compared to Sp6 created databases.
32 Missing Primary Key Constraints (Mostly due to unused tables not used in Sp7):
Missing / changed PRIMARY KEYs: 35
The following tables were identified in the schema diff but were not added in this PR because they are legacy, client specific, or no longer used by current Specify workflows:
These tables appear to not be required for new database creation or normal application operation, but let me know if any of these should be added.
Checklist
self-explanatory (or properly documented)
Testing instructions
mariadb-dump -uroot -proot --no-data db_name > dbname_schema.sql